<template>
  <div class="login">
    <div class="login_context">
      <div class="login_logo">
        <img src="../../assets/img/logo.png" alt="">
      </div>
      <el-form class="login_box" :model="form" label-width="120">
        <el-form-item label="用户名">
          <el-input prefix-icon="el-icon-user" v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input prefix-icon="el-icon-lock" v-model="form.password" type="password"></el-input>
        </el-form-item>
        <el-form-item align="center">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="info" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { getMenu } from 'network/permission.js'
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    login() {
      getMenu(this.form)
        .then(res => {
          if(res.data.code === -999) {
            this.$message.error(res.data.data.message)
            return
          } else {
            this.$message({
              message: '登录成功',
              type: 'success'
            });
            this.$router.push('/main/home')
          }
        }, err => {
          console.log(err);
        })
    },
    reset() {
      this.form.username = ""
      this.form.password = ""
    }
  }
}
</script>

<style lang="scss" scoped>
.login {
  height: 100%;
  background-color: #3e6892;
  .login_context {
    width: 450px;
    height: 300px;
    background: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    border-radius: 10px;
    box-shadow: 0 0 5px 2px #ddd;
    .login_logo {
          width: 120px;
          height: 120px;
          position: absolute;
          top: -75px;
          left: 50%;
          margin-left: -75px;
          border-radius: 50%;
          padding: 10px;
          background: #fff;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background: #eee;
      }
    }
    .login_box {
      width: 100%;
      position: absolute;
      bottom: 0;
      padding: 0 20px;
      box-sizing: border-box;
    }
  }
}
</style>
